﻿using System.IO;
using ProtoBuf;

/// <summary>
/// protobuf的工具类
/// </summary>
/// 
namespace Server
{
    class ProtoHelper
    {
        //protobuf的序列化
        public static byte[] Serialize<T>(T t) where T : IExtensible
        {
            using (MemoryStream stream = new MemoryStream())
            {
                Serializer.Serialize<T>(stream, t);
                return stream.ToArray();
            }
        }

        //protobuf的反序列化
        public static T Deserialize<T>(byte[] bytes) where T : IExtensible
        {
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                T p = Serializer.Deserialize<T>(ms);
                return p;
            }
        }
    }
}

